package org.wattdepot.cli.commands;

import java.util.List;
import org.wattdepot.client.WattDepotClient;

/**
 * This class contains a command that prints out the help for the CommandLineInterface.
 * 
 * @author David Mau
 */
public class HelpCommand implements WattDepotCliCommand {
  // Default client-server connection to use unless given one.
  private WattDepotClient client = new WattDepotClient(debug);

  /**
   * This constructor makes sure that the client really is connected to the server.
   * 
   * @param anotherClient Specifies if the user wants to use another WattDepot server
   * other than the default simulation one.
   */
  public HelpCommand( String anotherClient ) {
    // If another client is provided
    if ( anotherClient != null ) {
      client = new WattDepotClient( anotherClient );
    }
    
    // Stop right away if we cannot contact server.
    if (!client.isHealthy()) {
      System.out.println("Failed to connect to " + client.getWattDepotUri());
      return;
    }
    // Indicate successful connection.
    //System.out.println("Connected to " + client.getWattDepotUri());
  }

  /**
   * The method that displays the help for the command line interface. Created by David Mau.
   * 
   * @param args A list of arguments given to this command
   * @return A String with the help command output in it.
   */
  public String doCommand(List<String> args) {
    String output;

    if (!args.isEmpty()) {
      output = tooManyArguments;
      output = output.concat(cr);
      return output;
    }

    output = "help";
    output = output.concat(cr);
    output = output.concat("  This message");
    output = output.concat(cr);
    output = output.concat("quit");
    output = output.concat(cr);
    output = output.concat("  Exits the system");
    output = output.concat(cr);
    output = output.concat("server {WattDepotServer}");
    output = output.concat(cr);
    output = output.concat("  Changes the current server to the specified server.");
    output = output.concat(cr);
    output = output.concat("sources");
    output = output.concat(cr);
    output = output.concat("  Prints a table summarizing the public sources in");
    output = output.concat(cr);
    output = output.concat("  the system, one per line.");
    output = output.concat(cr);
    output = output.concat("source {source} summary");
    output = output.concat(cr);
    output = output.concat("  Prints information about a single source.");
    output = output.concat(cr);
    output = output.concat("sensordata {source} timestamp {timestamp}");
    output = output.concat(cr);
    output = output.concat("  Prints information about a single sensor data instance.");
    output = output.concat(cr);
    output = output.concat("dailysensordata {source} day {day}");
    output = output.concat(cr);
    output = output.concat("  Prints a table listing all of the sensor data ");
    output = output.concat(cr);
    output = output.concat("  instances for the specified day.");
    output = output.concat(cr);
    output = output.concat("power {source} timestamp {timestamp}");
    output = output.concat(cr);
    output = output.concat("  Prints the power generated by the source at the given timestamp.");
    output = output.concat(cr);
    output = output.concat("powerstats {source} day {day} sampling-interval ");
    output = output.concat("{minutes} statistic {max|min|average}");
    output = output.concat(cr);
    output = output.concat("  Returns the maximum, minimum, or average power ");
    output = output.concat(cr);
    output = output.concat("  generated by the source for the day.");
    output = output.concat(cr);
    output = output.concat("total [carbon|energy] {source} day {day} ");
    output = output.concat("sampling-interval {minutes}");
    output = output.concat(cr);
    output = output.concat("  Returns the total amount of carbon (or energy) emitted ");
    output = output.concat(cr);
    output = output.concat("  by this source for the given day.");
    output = output.concat(cr);
    output = output.concat("chart power [generated|consumed] {source} {startday} {endday} ");
    output = output.concat("sampling-interval {minutes} file {file}");
    output = output.concat(cr);
    output = output.concat("  Writes out an html file that will display a chart illustrating ");
    output = output.concat(cr);
    output = output.concat("  the power for the source over the interval.");
    output = output.concat(cr);
    output = output.concat("fueltypes {source}");
    output = output.concat(cr);
    output = output.concat("  Returns a table of fuels associated with this source.");
    output = output.concat(cr);
    output = output.concat("  Returns the total power generated by the given fuel type. ");
    output = output.concat(cr);
    output = output.concat("totalpower {source} {timestamp} fueltype {fueltype}");
    output = output.concat(cr);
    output = output.concat("  Generates the total power generated by all non-virtual sources");
    output = output.concat(cr);
    output = output.concat("  associated with this source that use the specified fuel type.");
    output = output.concat(cr);
    output = output.concat("carboncontent {source} {timestamp} sampling-interval {interval}");
    output = output.concat(cr);
    output = output.concat("  Returns the total carbon that would be emitted by that source");
    output = output.concat(cr);
    output = output.concat("  over an hour at the rate occurring as of the timestamp.");
    output = output.concat(cr);
    output = output.concat("energyusage {source} day {start} {end} statistic {max|min}");
    output = output.concat(cr);
    output = output.concat("  Returns the maximum or minimum of power generated by the source");
    output = output.concat(cr);
    output = output.concat("  for the duration.  It checks at the top of the hour and will also");
    output = output.concat(cr);
    output = output.concat("  return when the source hit that maximum or minimum.");
    output = output.concat(cr);
    output = output.concat("energygenerated {source} day {start} {end} statistic {max|min}");
    output = output.concat(cr);
    output = output.concat("  Returns the maximum or minimum of energy generated by the source");
    output = output.concat(cr);
    output = output.concat("  for the duration.  It checks every day started at midnight in the");
    output = output.concat(cr);
    output = output.concat("  duration and samples every 1 hour for that day until midnight of");
    output = output.concat(cr);
    output = output.concat("  the next day.  It will also return the day when the source hit");
    output = output.concat(cr);
    output = output.concat("  that maximum or minimum.");
    output = output.concat(cr);
    output = output.concat("carbonemitted {source} day {start} {end} statistic {max|min}");
    output = output.concat(cr);
    output = output.concat("  Returns the maximum or minimum of carbon emitted by the source");
    output = output.concat(cr);
    output = output.concat("  for the duration.  It checks every day started at midnight in the");
    output = output.concat(cr);
    output = output.concat("  duration and samples every 1 hour for that day until midnight of");
    output = output.concat(cr);
    output = output.concat("  the next day.  It will also return the day when the source hit");
    output = output.concat(cr);
    output = output.concat("  that maximum or minimum.");
        
    return output;
  }

}
